<template>
	<div class="clueSelection">
    <!-- 潜客选择 -->
		<TopFilter
			:list="topFilterList"
			:cols="2"
			:collapse="false"
			@filterChange="changeHandle"
		/>

    <div style="margin-bottom: 60px">
      <FilterTable
        ref="table"
        selectionType="single"
        :onRowSelectChange="selectChange"
        :fetchapi="fetchApi"
        :params="fetchParams"
        :columns="columns"
        :datakey="'records'"
        :onColumnsChange="columns => this.columns = columns"
      />
    </div>


		<div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDialog">取 消</el-button>
      <el-button :disabled="this.isChoice" @click="saveDialog" type="primary">保 存</el-button>
    </div>

	</div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { selectionClues } from '@/api/retail/salesmanage/salesordermanage';
export default {
	name: 'clueSelection',
  mixins: [dictionary],
  props: {
    consultantList:{
      type: Array,
      default: []
    }
  },
	data (){
		return {
			topFilterList: this.createTopFilters(),
			columns: this.createTableColumns(),
      fetchParams: {},
      fetchApi: selectionClues,
      selectedRows: [], //选中列表中的行
      isChoice: true, //按钮是否可以选择

		}
	},
  created (){
    this.init();
  },
	methods: {
    init (){
      this.topFilterList[0].itemList = this.consultantList
      // getSalesConsultant().then( res => {
      //   this.topFilterList[0].itemList = res.data.map(x => ({ value: x.employeeNo, text: x.employeeName }));
      //   // console.log(this.formList[4])
      // }).catch( err => {
      //   // console.log(err)
      // })
    },
    selectChange (rows){ //选中时触发的函数
      this.selectedRows = rows;
      this.isChoice = this.selectedRows.length > 0? false: true;
    },
		createTopFilters (){ //搜索参数
			return [
				{
          type: 'SELECT',
          label: '销售顾问',
          fieldName: 'consult',
          placeholder: '请选择...',
          itemList: [{ text: '请选择', value: '1' }],
        },
        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'customerName',
          placeholder: '请输入...',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '手机号码',
          fieldName: 'mobilePhone',
          placeholder: '请输入...',
          initialValue: '',
        },
			]
		},
		createTableColumns (){ //表格参数
			return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '客户编号',
          dataIndex: 'potentialCustomerNo',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '客户名称',
          dataIndex: 'customerName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '客户来源',
          dataIndex: 'clueName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '意向级别',
          dataIndex: 'intentLevel',
          sorter: true,
          filter: true,
          filterType: 'input',
          filterItems: this.createDictList('1519'),
	        render: props => {
	          return <span>{this.createDictText(props.row.intentLevel, '1519')}</span>;
	        }
        },
        {
          title: '手机号',
          dataIndex: 'mobilePhone',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '销售顾问',
          dataIndex: 'consultant',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '了解途径',
          dataIndex: 'waysToRoad',
          sorter: true,
          filter: true,
          filterType: 'input',
        }
			]
		},
		changeHandle(val){ //所搜函数
      console.log('搜索的参数：', val)
      this.fetchParams = Object.assign({}, val);
    },
    closeDialog(param) { //取消
        this.$emit('close2', false, param);
    },
    saveDialog (){ //保存
      // console.log('保存')
      if(this.selectedRows.length > 0){
        this.$emit('close', false, this.selectedRows)
      }else {
        this.$emit('close', false)
      }
    },

	},

}
</script>

<style scoped="scoped" lang="less">
</style>
